package com.xjtu.platform.user.consultor.visitRecord;


import com.xjtu.platform.common.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/consultor/visitRecord")
public class visitRecordAPI {

    @Resource
    private VisitRecordService visitRecordService;

    @Resource
    private CommonService commonService;

    @PostMapping("/getInfo")
    public Result getFirstVisitInfo(@RequestHeader String token,@RequestBody VisitRecordDto visitRecordDto){
        String user_id = TokenUtils.getUserInfo(token,commonService).getUserId();
        visitRecordDto.setUser_id(user_id);
        Map<String,Object> page = visitRecordService.getInfo(visitRecordDto);

        return Result.success(page);
    }

    @PostMapping("/finishVisit")
    public Result finishVisit(@RequestHeader String token, @RequestBody FinishVisitDto finishVisitDto){
        String user_id = TokenUtils.getUserInfo(token,commonService).getUserId();
        boolean isRight = visitRecordService.insertResult(finishVisitDto);
        if(isRight){
            visitRecordService.sendMail(finishVisitDto);
            return Result.success("登记成功");
        }else {
            return Result.fail(Result.ERR_CODE_SYS,"系统维护中.......");
        }
    }

    @PostMapping("/getVisitInfo")
    public Result getVisitInfo(@RequestBody InfoDto infoDto){
        List<FinishVisitDto> list = visitRecordService.getVisitInfo(infoDto);
        return Result.success(list);
    }
}
